<{include file="Public/head.tpl"}>
</head>
<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    <b>天天生活</b>餐饮系统
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">
    <p class="login-box-msg">请输入登录信息</p>

    <form action="" method="post">
      <div class="form-group has-feedback">
        <input type="text" class="form-control" id="username" placeholder="请输入用户名">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" class="form-control" id="password" placeholder="请输入登录密码">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="box-footer">
          <button type="button" id="login_btn" class="btn btn-primary btn-block btn-flat" onclick="login();">登录</button>
        </div>
        <!-- /.col -->
      </div>
    </form>

  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 2.1.4 -->
<script src="/admin/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="/admin/bootstrap/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="/admin/plugins/iCheck/icheck.min.js"></script>
<script src="http://cdn.bootcss.com/bootbox.js/4.4.0/bootbox.min.js"></script>
<script>
    $(document).keyup(function(event){
        if(event.keyCode ==13){
            login();
        }
    });
    function login() {
		bootbox.setLocale("zh_CN");
	    var posturl = window.location.href;
		var username = document.getElementById("username").value;
		var password = document.getElementById("password").value;

		if (username == ''){
			bootbox.alert("用户名不能为空"); 
			return;
		}
		if (password == ''){
			bootbox.alert("密码不能为空");
			return;
		}

		$.ajax({
			url : posturl,
			type : 'post',
			data : 'username=' + username
					+ '&password=' + password,
			success : function(data) {
				var ret = JSON.parse(data);
				if (ret.status == 1) {
					bootbox.alert(ret.data);
					setTimeout(function(){window.location.href="/admin/index/index"}, 2000);
				} else {
					bootbox.alert(ret.data);
				}
			}
		});
	}
</script>
</body>
</html>
